package com.iw.test.freemarker;

import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FreeMarkerTest_01 {
	@Test
	public void firstTest() {
		Configuration configuration = new Configuration();
		configuration.setObjectWrapper(new DefaultObjectWrapper());
		configuration.setTemplateLoader(new ClassTemplateLoader(Test.class, "/imilk"));
		try {
			Template template = configuration.getTemplate("01.html");
			StringWriter writer = new StringWriter();
			Map<String, Object> context = new HashMap<String, Object>();

			context.put("message", "我的第一个FreeMarker程序");

			template.process(context, writer);
			System.out.println(writer.toString());
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TemplateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
